In [1]:
import pandas as pd
import numpy as np
from pandas_datareader import data
In [2]:
goog = data.DataReader('GOOG', start='2004', end='2018', data_source='yahoo')
goog.head()
Out[2]:
In [3]:
goog_p = goog['Adj Close']
In [20]:
%matplotlib inline
import matplotlib.pyplot as plt
plt.style.use('seaborn-ticks')
import seaborn; seaborn.set_style('whitegrid')
In [21]:
goog_p.plot(figsize=(15,10))
Out[21]:
In [25]:
goog_p = goog_p.asfreq('D', method='pad')
ROI = 100 * (goog_p.tshift(-365)/goog_p - 1)
ROI.plot(figsize=(15, 10))
plt.ylabel('% Return on Investment');
In [26]:
y1_return = goog['Adj Close'].pct_change().rolling(365).sum().dropna()
y1_vol = goog['Adj Close'].pct_change().rolling(365).std().dropna()
In [27]:
plt.figure(figsize=(15, 10))
seaborn.distplot(y1_return*100)
plt.ylabel('% Yearly Rolling Return')
plt.title('GOOG Historical Returns');